import 'package:flutterdemo/models/entity/compare_entity.dart';

compareEntityFromJson(CompareEntity data, Map<String, dynamic> json) {
	if (json['error_code'] != null) {
		data.errorCode = json['error_code'] is String
				? int.tryParse(json['error_code'])
				: json['error_code'].toInt();
	}
	if (json['error_msg'] != null) {
		data.errorMsg = json['error_msg'].toString();
	}
	if (json['log_id'] != null) {
		data.logId = json['log_id'] is String
				? int.tryParse(json['log_id'])
				: json['log_id'].toInt();
	}
	if (json['timestamp'] != null) {
		data.timestamp = json['timestamp'] is String
				? int.tryParse(json['timestamp'])
				: json['timestamp'].toInt();
	}
	if (json['cached'] != null) {
		data.cached = json['cached'] is String
				? int.tryParse(json['cached'])
				: json['cached'].toInt();
	}
	if (json['result'] != null) {
		data.result = new CompareResult().fromJson(json['result']);
	}
	return data;
}

Map<String, dynamic> compareEntityToJson(CompareEntity entity) {
	final Map<String, dynamic> data = new Map<String, dynamic>();
	data['error_code'] = entity.errorCode;
	data['error_msg'] = entity.errorMsg;
	data['log_id'] = entity.logId;
	data['timestamp'] = entity.timestamp;
	data['cached'] = entity.cached;
	if (entity.result != null) {
		data['result'] = entity.result.toJson();
	}
	return data;
}

compareResultFromJson(CompareResult data, Map<String, dynamic> json) {
	if (json['score'] != null) {
		data.score = json['score'] is String
				? double.tryParse(json['score'])
				: json['score'].toDouble();
	}
	if (json['face_list'] != null) {
		data.faceList = new List<CompareResultFaceList>();
		(json['face_list'] as List).forEach((v) {
			data.faceList.add(new CompareResultFaceList().fromJson(v));
		});
	}
	return data;
}

Map<String, dynamic> compareResultToJson(CompareResult entity) {
	final Map<String, dynamic> data = new Map<String, dynamic>();
	data['score'] = entity.score;
	if (entity.faceList != null) {
		data['face_list'] =  entity.faceList.map((v) => v.toJson()).toList();
	}
	return data;
}

compareResultFaceListFromJson(CompareResultFaceList data, Map<String, dynamic> json) {
	if (json['face_token'] != null) {
		data.faceToken = json['face_token'].toString();
	}
	return data;
}

Map<String, dynamic> compareResultFaceListToJson(CompareResultFaceList entity) {
	final Map<String, dynamic> data = new Map<String, dynamic>();
	data['face_token'] = entity.faceToken;
	return data;
}